﻿using Microsoft.UI.Xaml.Data;

namespace DimensionsHelper.Client.WinUi.Helpers;

public partial class StringFormatConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        if (parameter is not string formatString || string.IsNullOrEmpty(formatString))
        {
            return value.ToString() ?? string.Empty;
        }

        try
        {
            return string.Format(formatString, value);
        }
        catch
        {
            return value.ToString() ?? string.Empty;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, string language) => value;
}